import { ArgumentsHost, ExceptionFilter, Injectable } from '@nestjs/common'
import { Result } from '../../entities/result'

/**
 * 统一异常结果
 */
@Injectable()
export class FailFilter implements ExceptionFilter {
  catch(exception: any, host: ArgumentsHost): any {
    const response = host.switchToHttp().getResponse()

    return response.json(Result.fail(exception.getStatus(), exception.response.message))
  }
}
